<?php

require_once 'mysql.inc.php';

function CurPersonSel($i, $current_string, $noncorrent_string="") {
    if (isset($_SESSION['pinfo'])) {
            if ($i==$_SESSION['pinfo']['id']) return $current_string ;
            else return $noncorrent_string;
    } elseif ($i = 0) return $current_string;
    else return $noncorrent_string;
}


// drop-down list selection
function GenerateChangePersonMenuItems($current_string, $inlude_all_option=null) {
    if ($inlude_all_option<>null) echo '<option value="0" '.CurPersonSel(0, $current_string).'> '.$inlude_all_option.'</option>';
    foreach ($_SESSION['Global']['People'] as $p){
        printf('<option value="%d" '.CurPersonSel($p['id'], $current_string).'>%s </option>', $p['id'], $p[':schedule-alias']);
    }   
}
function GenerateChangePersonForm($action){
    if ( AmIAdmin() ) { 
        echo '<form  name="form_action_VyberClovek"  action="'.$action.'" method="POST">';
        echo '<select name="form_action_VyberClovek" onChange="document.form_action_VyberClovek.submit();">';
        GenerateChangePersonMenuItems('selected = "selected"','Všichni');
        echo '</select>';
        echo '</form>';
    }
}

// list of checkboxes
function GenerateChangePersonCheckboxesTable($var, $columns=5) {
    $i=1;
    echo "<tr>";
    foreach ($_SESSION['Global']['People'] as $p){
        printf('<td  title="%s"><input  type="checkbox" value="%s" name="%s[]" %s>%s</input></td>',
                PersonName($p), $p['id'],  $var,   CurPersonSel($p['id'], 'checked="checked"'), $p[':schedule-alias']);
        if (($i++ % $columns ) ==  0 ) echo "</tr><tr>";
    } 
    echo "</tr>";


}

?>